use std::{
    fs::ReadDir,
    path::{Path, PathBuf},
    sync::Arc,
};

use QcUI::core::context::UiContext;

use crate::{components::dock::DockView, core::context::Context};

#[derive(Debug)]
pub struct ResPreviewPanel {
    context: Arc<Context>,
    current_dir: PathBuf,
    files: ReadDir,
}

impl DockView for ResPreviewPanel {
    fn render(&mut self, ctx: &mut UiContext, show_tab: bool) {
        ctx.ui.horizontal_wrapped(|ui| {
            for file in self.current_dir.read_dir().unwrap() {
                if let Ok(file) = file {
                    ui.label(file.file_name().into_string().unwrap());
                }
            }
        });
    }
}

impl ResPreviewPanel {
    pub fn new(context: Arc<Context>) -> Self {
        let binding = context.clone();
        let config = binding.project_config.try_read().unwrap();
        let path = config.as_ref().unwrap().path.as_ref().unwrap();
        let current_dir = path.clone();
        let files = current_dir.read_dir().unwrap();
        Self {
            context,
            current_dir,
            files,
        }
    }
}
